package com.wisecoach.gatewayplus.transaction.tx;

import com.wisecoach.gatewayplus.transaction.AbstractSubmittedTxProcessor;
import com.wisecoach.gatewayplus.transaction.InvalidTransactionHandler;
import com.wisecoach.gatewayplus.transaction.SubmitTxContext;
import org.hyperledger.fabric.client.Status;

import static org.hyperledger.fabric.protos.peer.TxValidationCode.VALID;

/**
 * {@code @author:} wisecoach
 * {@code @date:} 2023/9/26 上午9:48
 * {@code @version:} 1.0.0
 */


public class TxSubmittedTxProcessor extends AbstractSubmittedTxProcessor {

    private final InvalidTransactionHandler invalidTransactionHandler;

    public TxSubmittedTxProcessor(InvalidTransactionHandler invalidTransactionHandler) {
        this.invalidTransactionHandler = invalidTransactionHandler;
    }

    /**
     * 只需要判断是否成功上链，失败交给invalidTransactionHandler处理
     */
    @Override
    protected void doProcess(SubmitTxContext ctx, Status status) {
        if (!VALID.equals(status.getCode())) {
            invalidTransactionHandler.handle(ctx, status);
        }
    }
}
